<?php

/**
 * 后台 会议酒店管理　模块 Model
 * ============================================================================
 * TBlog TBlog博客系统　BY Tmac PHP MVC framework
 * $Author: zwt007 $  <zwttmac@qq.com>
 * $Id: casemodel.class.php 31 2011-07-11 15:25:51Z zwt007 $
 * http://www.t-mac.org；
 */
class hotel extends Model
{

    private $class_table;
    private $article_table;
    private $addonimages_table;

    /**
     * 初始化变量　定义私有变量
     */
    public function _init()
    {
        //连接数据库
        $this->connect();
        $this->class_table = '#@__category';
        $this->article_table = '#@__article';
        $this->addonimages_table = '#@__addonimages';
    }

    /**
     * 保存
     * @param string $menusMain
     * return Boole
     */
    public function addArticle($table, $info, $mode = 'INSERT', $where = '')
    {
        if ($table == 'article') {
            $table = $this->article_table;
        } else {
            $table = $this->addonimages_table;
        }
        $rs = $this->db->autoExecute($table, $info, $mode, $where);
        return $rs;
    }

    /**
     * 保存返回article_id
     * @param string $menusMain
     * return Boole
     */
    public function addArticleReturn($info)
    {
        $rs = $this->db->autoInsertReturn($this->article_table, $info);
        return $rs;
    }

    /**
     * 获取一个资讯栏目信息
     * @param int $class_id 栏目id
     * return array
     */
    public function getArticleInfo($aid)
    {
        $rs = $this->db->getRow("SELECT a.*, b.imgurls, b.content, b.star, b.address FROM $this->article_table a LEFT JOIN $this->addonimages_table b ON a.article_id = b.article_id WHERE a.article_id = '$aid' LIMIT 0,1");
        return $rs;
    }

    /**
     * 获取资讯栏目
     * return article_class,pages
     */
    public function getClass()
    {
        $rs = $this->db->getAll("SELECT * FROM $this->class_table ORDER BY cat_order DESC, cat_id DESC");
        return $rs;
    }


    /**
     * 取省列表 或根据省id取城市列表
     * @param <type> $type  默认c取city列表 p取province列表
     * @param <int>  $pid   省级id
     * @return array
     */
    public function getCity($type = 'c', $pid = null)
    {
        if ($type == 'p') {
            $rs = $this->db->getAll("SELECT Pid, Pname, suoxie FROM $this->city_table WHERE province = 1");
        } else {
            $rs = $this->db->getAll("SELECT cityid, cityname, suoxie FROM $this->city_table WHERE pid = $pid ORDER BY province DESC, abcd ASC");
        }
        return $rs;
    }

    /**
     * del
     * @param int $class_id
     */
    public function delArticle($id)
    {
        $rs = $this->db->execute("DELETE FROM $this->article_table WHERE article_id in ($id)");
        $rs = $this->db->execute("DELETE FROM $this->addonimages_table WHERE article_id in ($id)");        
        return $rs;
    }

    //取出configbody字段里的值
    public function getCfgBody($value, $configbody)
    {
        preg_match_all('/{' . $value . ' key="(.*)"}(.*){\/' . $value . '}/isU', $configbody, $result);
        return $result;
    }

}